package handler

import (
	"context"
	dev "qld2devservice/proto"
	"qld2devservice/service"
	"qld2devservice/utils"
)

// apiController 控制器
type handlerDevOrderController struct{}

func NewDevOrderController() dev.DevOrderServer {
	return &handlerDevOrderController{}
}

// AutoFinishDevOrder 自动结束订单
func (that *handlerDevOrderController) AutoFinishDevOrder(ctx context.Context, p *dev.AutoFinishDevOrderRequest) (res *dev.AutoFinishDevOrderResponse, err error) {
	utils.MyPrint(utils.PRINT_INFO, "AutoFinishDevOrder request", utils.TransProtoToJson(p))
	res = &dev.AutoFinishDevOrderResponse{}
	defer func() {
		utils.MyPrint(utils.PRINT_INFO, "AutoFinishDevOrder response", utils.TransProtoToJson(res))
		if err != nil {
			service.PutErrorMsg("AutoFinishDevOrder"+err.Error(), p.SnNum, service.UserControlErr)
		}
	}()
	var retCode int64
	retCode, res.ErrMsg, res.OrderId = service.AutoFinishChargerOrder(p.SnNum, p.OrderSn, p.Amount, p.Duration, p.FinishType, float64(p.Electricity), p.AmountRecord, p.FinishMsg)
	res.RetCode = int32(retCode)
	return res, nil
}
